package com.hzncc.scaffold.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.hzncc.scaffold.core.ResultT;
import com.hzncc.scaffold.entity.Other.Task;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hzncc.scaffold.entity.Vo.ContinueVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * <p>
 * 任务表 Mapper 接口
 * </p>
 *
 * @author DrunkBear
 * @since 2022-04-27
 */
@Component
public interface TaskMapper extends BaseMapper<Task> {

        @Select("SELECT\n" +
                "\ttask.id,\n" +
                "\ttaskprogress.isFinished,\n" +
                "\ttask.paperId,\n" +
                "\ttask.rank,\n" +
                "\ttask.resourceUrl,\n" +
                "\ttask.title,\n" +
                "\ttask.type\n" +
                "FROM\n" +
                "\ttask\n" +
                "LEFT JOIN taskprogress ON taskprogress.taskId = task.id\n ${ew.customSqlSegment}")
        public ContinueVo continueCourse(@Param(Constants.WRAPPER) QueryWrapper queryWrapper);



//        @Select("SELECT\n" +
//                "\ttask.id,\n" +
//                "\ttaskprogress.isFinished,\n" +
//                "\ttask.paperId,\n" +
//                "\ttask.rank,\n" +
//                "\ttask.resourceUrl,\n" +
//                "\ttask.title,\n" +
//                "\ttask.type\n" +
//                "FROM\n" +
//                "\ttask\n" +
//                "LEFT JOIN taskprogress ON taskprogress.taskId = task.id\n ${ew.customSqlSegment}")
//        public List<ContinueVo> continueCourseList(@Param(Constants.WRAPPER) QueryWrapper queryWrapper);

        @Select("SELECT\n" +
                "\ttask.id,\n" +
                "\ttaskprogress.isFinished,\n" +
                "\ttask.paperId,\n" +
                "\ttask.rank,\n" +
                "\ttask.resourceUrl,\n" +
                "\ttask.title,\n" +
                "\ttask.type \n" +
                "FROM\n" +
                "\ttaskprogress\n" +
                "\tLEFT JOIN task ON taskprogress.taskId = task.id \n" +
                "\t \n ${ew.customSqlSegment}")
        public List<ContinueVo> continueCourseList(@Param(Constants.WRAPPER) QueryWrapper queryWrapper);


        @Select("SELECT max(`rank`) AS `max` FROM `task` WHERE `chapterId` = #{chapterId}")
        public Integer queryTask(@Param("chapterId") Integer chapterId);

}
